home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / utils / xad / developer / sources / clients / xdisk.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  5KB  |  191 lines

  1. #ifndef XADMASTER_XDISK_C
  2. #define XADMASTER_XDISK_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        xDisk.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: xDisk.c 1.1 (04.02.1999)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    xDisk disk archiver client
  12.  
  13.  1.0   05.09.98 : first version
  14.  1.1   04.02.99 : new InfoText system
  15. */
  16.  
  17. #include <proto/xadmaster.h>
  18. #include <dos/dos.h>
  19. #include "SDI_compiler.h"
  20. #include "xpkstuff.c"
  21.  
  22. #ifndef XADMASTERFILE
  23. #define xDisk_Client        FirstClient
  24. #define NEXTCLIENT        0
  25. UBYTE version[] = "$VER: xDisk 1.1 (04.02.1999)";
  26. #endif
  27. #define XDISK_VERSION        1
  28. #define XDISK_REVISION        1
  29.  
  30. struct xDisk {
  31.   ULONG            xd_Header;    /* equals 'XDS0' */
  32.   struct DateStamp    xd_Date;    /* date of creation */
  33.   ULONG            xd_PackTime;    /* in seconds */
  34.   UWORD            xd_AttnFlags;    /* ExecBase->AttnFlags */
  35.   UWORD            xd_SoftVer;    /* ExecBase->SoftVer */
  36.   ULONG            xd_CylinderSize; /* Size of one cylinder */
  37.   ULONG            xd_NumCylinders; /* Number of cylinders */
  38.   ULONG            xd_InfoTextSize; /* no text == 0 */
  39.   ULONG            xd_LowCyl;    /* lowest crunched cylinder */
  40.   ULONG            xd_HighCyl;    /* highest crunched Cylinder */
  41. };
  42.  
  43. /* After tha xDisk structure the packed data follows. First the
  44.    XPK-Crunched info-text (when available) and the each cylinder as a
  45.    XPKF-block.
  46.    NOTE: It seems that sometimes xDisk adds xd_InfoTextSize, also when no
  47.    text was added!
  48. */
  49.  
  50. ASM(BOOL) xDisk_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  51. REG(a6, struct xadMasterBase *xadMasterBase))
  52. {
  53.   if(((ULONG *) data)[0] == 0x58445330)
  54.     return 1;
  55.   else
  56.     return 0;
  57. }
  58.  
  59. ASM(LONG) xDisk_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  60. REG(a6, struct xadMasterBase *xadMasterBase))
  61. {
  62.   LONG err;
  63.   ULONG dat[9];
  64.   ULONG num = 0;
  65.   struct xDisk xd;
  66.   struct xadDiskInfo *xdi;
  67.  
  68.   if(!(xdi = (struct xadDiskInfo *) xadAllocObjectA(XADOBJ_DISKINFO, 0)))
  69.     return XADERR_NOMEMORY;
  70.   ai->xai_DiskInfo = xdi;
  71.  
  72.   if((err = xadHookAccess(XADAC_READ, sizeof(struct xDisk), &xd, ai)))
  73.     return err;
  74.   xdi->xdi_EntryNumber = 1;
  75.   xdi->xdi_Cylinders = xd.xd_NumCylinders;
  76.   xdi->xdi_LowCyl = xd.xd_LowCyl;
  77.   xdi->xdi_HighCyl = xd.xd_HighCyl;
  78.   xdi->xdi_SectorSize = 512; /* most devices should use 512 as blocksize */
  79.   xdi->xdi_CylSectors = xd.xd_CylinderSize>>9;
  80.   xdi->xdi_TotalSectors = xd.xd_NumCylinders*xdi->xdi_CylSectors;
  81.   xdi->xdi_Flags = XADDIF_GUESSHEADS|XADDIF_GUESSTRACKSECTORS;
  82.   if(xdi->xdi_CylSectors & 1)
  83.   {
  84.     xdi->xdi_Heads = 1;
  85.     xdi->xdi_TrackSectors = xdi->xdi_CylSectors;
  86.   }
  87.   else
  88.   {
  89.     xdi->xdi_Heads = 2;
  90.     xdi->xdi_TrackSectors = xdi->xdi_CylSectors>>1;
  91.   }
  92.  
  93.   while(ai->xai_InPos < ai->xai_InSize)
  94.   {
  95.     if((err = xadHookAccess(XADAC_READ, 36, dat, ai)))
  96.       return err;
  97.     if((err = xadHookAccess(XADAC_INPUTSEEK, dat[1]-28, 0, ai)))
  98.       return err;
  99.     ++num;
  100.     if(dat[8] & (1<<25)) /* check for password flag in every entry */
  101.     {
  102.       ai->xai_Flags |= XADAIF_CRYPTED;
  103.       xdi->xdi_Flags |= XADDIF_CRYPTED;
  104.     }
  105.   }
  106.   if((err = xadHookAccess(XADAC_INPUTSEEK, sizeof(struct xDisk) -
  107.   ai->xai_InPos, 0, ai)))
  108.     return err;
  109.   dat[0] = xdi->xdi_HighCyl+1-xdi->xdi_LowCyl;
  110.   if(num == dat[0]+1) /* decrunch infotext and store pointer */
  111.   {
  112.     struct xadTextInfo *ti;
  113.     if((ti = (struct xadTextInfo *) xadAllocObjectA(XADOBJ_TEXTINFO, 0)))
  114.     {
  115.       LONG err;
  116.  
  117.       if((err = xpkDecrunch(&ti->xti_Text, &ti->xti_Size, ai,
  118.       xadMasterBase)))
  119.         xadFreeObjectA(ti, 0);
  120.       else
  121.         xdi->xdi_TextInfo = ti;
  122.       return err;
  123.     }
  124.     else
  125.       return XADERR_NOMEMORY;
  126.   }
  127.   else if(num != dat[0])
  128.     return XADERR_ILLEGALDATA;
  129.  
  130.   return 0;
  131. }
  132.  
  133. ASM(LONG) xDisk_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  134. REG(a6, struct xadMasterBase *xadMasterBase))
  135. {
  136.   LONG i, err = 0, u;
  137.   struct {
  138.     STRPTR a;
  139.     ULONG  s;
  140.   } dat;
  141.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  142.  
  143.   u = ai->xai_InPos;
  144.  
  145.   /* skip entries */
  146.   for(i = ai->xai_CurDisk->xdi_LowCyl; !err && i < ai->xai_LowCyl; ++i)
  147.   {
  148.     if(!(err = xadHookAccess(XADAC_READ, 8, &dat, ai)))
  149.       err = xadHookAccess(XADAC_INPUTSEEK, dat.s, 0, ai);
  150.   }
  151.  
  152.   for(; !err && i <= ai->xai_HighCyl; ++i)
  153.   {
  154.     if(!(err = xpkDecrunch(&dat.a, &dat.s, ai, xadMasterBase)))
  155.     {
  156.       err = xadHookAccess(XADAC_WRITE, dat.s, dat.a, ai);
  157.       FreeVec(dat.a);
  158.     }
  159.   }
  160.  
  161.   /* seek back to start */
  162.   if(!err)
  163.     err = xadHookAccess(XADAC_INPUTSEEK, u-ai->xai_InPos, 0, ai);
  164.  
  165.   return err;
  166. }
  167.  
  168. ASM(void) xDisk_Free(REG(a0, struct xadArchiveInfo *ai),
  169. REG(a6, struct xadMasterBase *xadMasterBase))
  170. {
  171.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  172.   if(ai->xai_DiskInfo)
  173.   {
  174.     if(ai->xai_DiskInfo->xdi_TextInfo)
  175.     {
  176.       FreeVec(ai->xai_DiskInfo->xdi_TextInfo->xti_Text);
  177.       xadFreeObjectA(ai->xai_DiskInfo->xdi_TextInfo, 0);
  178.     }
  179.     xadFreeObjectA(ai->xai_DiskInfo, 0);
  180.     ai->xai_DiskInfo = 0; /* clear the entry */
  181.   }
  182. }
  183.  
  184. struct xadClient xDisk_Client = {
  185. NEXTCLIENT, XADCLIENT_VERSION, 1, XDISK_VERSION, XDISK_REVISION, 4,
  186. XADCF_DISKARCHIVER, XADCID_XDISK, "xDisk", (BOOL (*)()) xDisk_RecogData,
  187. (LONG (*)()) xDisk_GetInfo, (LONG (*)()) xDisk_UnArchive,
  188. (void (*)()) xDisk_Free};
  189.  
  190. #endif /* XADASTER_XDISK_C */
  191.